﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Objects;
using Bundled.Entity;
using Bundled.ORM;

namespace Bundled.Pages.Products
{
    public partial class Default : System.Web.UI.Page
    {
        ShoppingCart sc;

        protected void Page_Load(object sender, EventArgs e)
        {
            using (BundledDBEntities context = new BundledDBEntities())
            {
                int categoryID = Convert.ToInt32(Request["category"]);
                var Products = from p in context.Products
                               where p.Category_ID == categoryID
                               select p;
                productList.DataSource = Products.ToList();
                productList.DataBind();
            }
            if (Session["Cart"] != null)
            {
                sc = (ShoppingCart)Session["Cart"];
            }
        }


        protected void productList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "AddCart")
            {
                int Product_id = Convert.ToInt32(e.CommandArgument);
                Label pName = (Label)e.Item.FindControl("productName");
                Label pPrice = (Label)e.Item.FindControl("productPrice");
                decimal pDPrice = Convert.ToDecimal(pPrice.Text);
                string pSName = pName.Text;
                ShoppingCart.AddToCart(Product_id, 1, pDPrice, pSName);
                Session["Cart"] = sc;
            }
        
        }

    }
}